#ifndef USEIO_H
#define USEIO_H


//===============================================
// First Motor Controller
//===============================================

#define OUT_BASE1		64
#define IN_BASE1		0x00		

#define IN_EX1			0x000
#define IN_EX2			0x100
#define IN_EX3			0x200
#define IN_EX4			0x300
#define IN_EX5			0x400
#define IN_EX6			0x500
#define IN_EX7			0x600

#define OUT_EX1			0x700
#define OUT_EX2			0x800
#define OUT_EX3			0x900
#define OUT_EX4			0xA00
#define OUT_EX5			0xB00
#define OUT_EX6			0xC00

//===============================================
// Second Motor Controller
//===============================================

#define IO_END_NO       0xD00
#define OUT_NO			0x700
#define IN_NO			0x00

//======================== I/O define format ==============================
//-----------------------------------------------------------------------------
/////////////////////////////    INPUT   //////////////////////////////////////
//-----------------------------------------------------------------------------
#define IN_E_STOP_SW									(IN_EX1 + 0x00)
#define IN_DOOR_OPEN									(IN_EX1 + 0x01)
#define IN_LOAD_MAGAZINE_LOCK_UNIT_FOR					(IN_EX1 + 0x02)
#define IN_LOAD_MAGAZINE_LOCK_UNIT_BACK					(IN_EX1 + 0x03)
#define	IN_LOAD_MAGAZINE_LOCK							(IN_EX1 + 0x04)
#define	IN_LOAD_MAGAZINE_UNLOCK							(IN_EX1 + 0x05)
#define IN_LOAD_MAGAZINE_LOCK_UNIT_UP					(IN_EX1 + 0x06)
#define IN_LOAD_MAGAZINE_LOCK_UNIT_DOWN					(IN_EX1 + 0x07)

#define IN_LOAD_LEFT_MAGAZINE_STATE_FOR					(IN_EX2 + 0x00)
#define	IN_LOAD_LEFT_MAGAZINE_STATE_BACK				(IN_EX2 + 0x01)
#define	IN_LOAD_RIGHT_MAGAZINE_STATE_FOR				(IN_EX2 + 0x02)
#define	IN_LOAD_RIGHT_MAGAZINE_STATE_BACK				(IN_EX2 + 0x03)
#define IN_LOAD_MAGAZINE_CENTERING_FOR					(IN_EX2 + 0x04)
#define	IN_LOAD_MAGAZINE_CENTERING_BACK					(IN_EX2 + 0x05)
#define IN_LOAD_CONVEYOR_STOPPER_UP						(IN_EX2 + 0x06)
#define IN_LOAD_CONVEYOR_STOPPER_DOWN					(IN_EX2 + 0x07)

//-----------------------------------------------------------------------------
// INPUT DEFINE (IO_NO X010 ~ X01F)
//-----------------------------------------------------------------------------
#define	IN_LOAD_MAGAZINE_IN_SENSOR_CHECK				(IN_EX3 + 0x00)
#define IN_LOAD_MAGAZINE_OUT_SENSOR_CHECK				(IN_EX3 + 0x01)
#define	IN_LOAD_MAGAZINE_STOPPER_SENSOR_CHECK			(IN_EX3 + 0x02)
#define IN_LOAD_MAGAZINE_COUNT_SENSING_CHECK			(IN_EX3 + 0x03)
#define IN_UNLOAD_LEFT_MAGAZINE_STATE_FOR				(IN_EX3 + 0x04)
#define IN_UNLOAD_LEFT_MAGAZINE_STATE_BACK				(IN_EX3 + 0x05)
#define IN_UNLOAD_RIGHT_MAGAZINE_STATE_FOR				(IN_EX3 + 0x06)
#define IN_UNLOAD_RIGHT_MAGAZINE_STATE_BACK				(IN_EX3 + 0x07)

#define IN_UNLOAD_MAGAZINE_CENTERING_FOR				(IN_EX4 + 0x00)
#define IN_UNLOAD_MAGAZINE_CENTERING_BACK				(IN_EX4 + 0x01)
#define IN_UNLOAD_MAGAZINE_LOCK							(IN_EX4 + 0x02)
#define IN_UNLOAD_MAGAZINE_UNLOCK						(IN_EX4 + 0x03)
#define IN_UNLOAD_MAGAZINE_LOCK_UNIT_UP					(IN_EX4 + 0x04)
#define IN_UNLOAD_MAGAZINE_LOCK_UNIT_DOWN				(IN_EX4 + 0x05)
#define IN_UNLOAD_MAGAZINE_LOCK_UNIT_FOR				(IN_EX4 + 0x06)
#define IN_UNLOAD_MAGAZINE_LOCK_UNIT_BACK				(IN_EX4 + 0x07)

//-----------------------------------------------------------------------------
// INPUT DEFINE (IO_NO X020 ~ X02F)
//-----------------------------------------------------------------------------
#define IN_RFID_FOR										(IN_EX5 + 0x00)
#define IN_RFID_BACK									(IN_EX5 + 0x01)
#define IN_UNLOAD_CONVEYOR_STOPPER_UP					(IN_EX5 + 0x02)
#define IN_UNLOAD_CONVEYOR_STOPPER_DOWN					(IN_EX5 + 0x03)
#define	IN_UNLOAD_MAGAZINE_IN_SENSOR_CHECK				(IN_EX5 + 0x04)
#define IN_UNLOAD_MAGAZINE_OUT_SENSOR_CHECK				(IN_EX5 + 0x05)
#define IN_UNLOAD_MAGAZINE_STOPPER_SENSOR_CHECK			(IN_EX5 + 0x06)
#define IN_SPARE_47										(IN_EX5 + 0x07)

#define IN_LOAD_CONVEYOR_RUN_STOP_CHECK					(IN_EX6 + 0x00)
#define	IN_UNLOAD_CONVEYOR_RUN_STOP_CHECK				(IN_EX6 + 0x01)
#define	IN_SPARE_52										(IN_EX6 + 0x02)
#define	IN_SPARE_53										(IN_EX6 + 0x03)
#define IN_SPARE_54										(IN_EX6 + 0x04)
#define IN_SPARE_55										(IN_EX6 + 0x05)
#define IN_SPARE_56										(IN_EX6 + 0x06)
#define IN_SPARE_57										(IN_EX6 + 0x07)

//-----------------------------------------------------------------------------
// INPUT DEFINE (IO_NO X020 ~ X02F)
//-----------------------------------------------------------------------------
#define IN_PIO_00										(IN_EX7 + 0x00)
#define	IN_PIO_01										(IN_EX7 + 0x01)
#define	IN_PIO_02										(IN_EX7 + 0x02)
#define	IN_PIO_03										(IN_EX7 + 0x03)
#define IN_PIO_04										(IN_EX7 + 0x04)
#define IN_PIO_05										(IN_EX7 + 0x05)
#define IN_PIO_06										(IN_EX7 + 0x06)
#define IN_PIO_07										(IN_EX7 + 0x07)





//-----------------------------------------------------------------------------
//////////////////////////////  OUTPUT   //////////////////////////////////////
//-----------------------------------------------------------------------------
// OUTPUT DEFINE (IO_NO  Y000 ~ Y00F)
//-----------------------------------------------------------------------------
#define	OUT_BZ_K1										(OUT_EX1 + 0x00)
#define OUT_SPARE_01									(OUT_EX1 + 0x01)
#define OUT_SPARE_02									(OUT_EX1 + 0x02)
#define OUT_SPARE_03									(OUT_EX1 + 0x03)
#define OUT_SPARE_04									(OUT_EX1 + 0x04)
#define OUT_SPARE_05									(OUT_EX1 + 0x05)
#define OUT_LOAD_MAGAZINE_LOCK_UNIT_FOR					(OUT_EX1 + 0x06)
#define OUT_LOAD_MAGAZINE_LOCK_UNIT_BACK				(OUT_EX1 + 0x07)

#define	OUT_LOAD_MAGAZINE_LOCK							(OUT_EX2 + 0x00)
#define	OUT_LOAD_MAGAZINE_UNLOCK						(OUT_EX2 + 0x01)
#define OUT_LOAD_MAGAZINE_LOCK_UNIT_UP					(OUT_EX2 + 0x02)
#define OUT_LOAD_MAGAZINE_LOCK_UNIT_DOWN				(OUT_EX2 + 0x03)
#define OUT_LOAD_LEFT_MAGAZINE_STATE_FOR				(OUT_EX2 + 0x04)
#define	OUT_LOAD_LEFT_MAGAZINE_STATE_BACK				(OUT_EX2 + 0x05)
#define	OUT_LOAD_RIGHT_MAGAZINE_STATE_FOR				(OUT_EX2 + 0x06)
#define	OUT_LOAD_RIGHT_MAGAZINE_STATE_BACK				(OUT_EX2 + 0x07)


//-----------------------------------------------------------------------------
// OUTPUT DEFINE (IO_NO X010 ~ X01F)
//-----------------------------------------------------------------------------
#define OUT_LOAD_MAGAZINE_CENTERING_FOR					(OUT_EX3 + 0x00)
#define	OUT_LOAD_MAGAZINE_CENTERING_BACK				(OUT_EX3 + 0x01)
#define OUT_LOAD_CONVEYOR_STOPPER_UP					(OUT_EX3 + 0x02)
#define OUT_LOAD_CONVEYOR_STOPPER_DOWN					(OUT_EX3 + 0x03)
#define OUT_UNLOAD_MAGAZINE_CENTERING_FOR				(OUT_EX3 + 0x04)
#define	OUT_UNLOAD_MAGAZINE_CENTERING_BACK				(OUT_EX3 + 0x05)
#define OUT_UNLOAD_MAGAZINE_LOCK_UNIT_FOR				(OUT_EX3 + 0x06)
#define OUT_UNLOAD_MAGAZINE_LOCK_UNIT_BACK				(OUT_EX3 + 0x07)


#define	OUT_UNLOAD_MAGAZINE_LOCK						(OUT_EX4 + 0x00)
#define	OUT_UNLOAD_MAGAZINE_UNLOCK						(OUT_EX4 + 0x01)
#define OUT_UNLOAD_MAGAZINE_LOCK_UNIT_UP				(OUT_EX4 + 0x02)
#define OUT_UNLOAD_MAGAZINE_LOCK_UNIT_DOWN				(OUT_EX4 + 0x03)
#define OUT_UNLOAD_LEFT_MAGAZINE_STATE_FOR				(OUT_EX4 + 0x04)
#define OUT_UNLOAD_LEFT_MAGAZINE_STATE_BACK				(OUT_EX4 + 0x05)
#define OUT_UNLOAD_RIGHT_MAGAZINE_STATE_FOR				(OUT_EX4 + 0x06)
#define OUT_UNLOAD_RIGHT_MAGAZINE_STATE_BACK			(OUT_EX4 + 0x07)

//-----------------------------------------------------------------------------
// OUTPUT DEFINE (IO_NO X020 ~ X02F)
//-----------------------------------------------------------------------------
#define OUT_UNLOAD_CONVEYOR_STOPPER_UP					(OUT_EX5 + 0x00)
#define OUT_UNLOAD_CONVEYOR_STOPPER_DOWN				(OUT_EX5 + 0x01)
#define OUT_RFID_FOR									(OUT_EX5 + 0x02)
#define OUT_RFID_BACK									(OUT_EX5 + 0x03)
#define OUT_SPARE_44									(OUT_EX5 + 0x04)
#define OUT_SPARE_45									(OUT_EX5 + 0x05)
#define OUT_LOAD_CONVEYOR_RUN_STOP						(OUT_EX5 + 0x06)
#define OUT_UNLOAD_CONVEYOR_RUN_STOP					(OUT_EX5 + 0x07)

#define OUT_PIO_00										(OUT_EX6 + 0x00)
#define OUT_PIO_01										(OUT_EX6 + 0x01)
#define	OUT_PIO_02										(OUT_EX6 + 0x02)
#define OUT_PIO_03										(OUT_EX6 + 0x03)
#define OUT_PIO_04										(OUT_EX6 + 0x04)
#define OUT_PIO_05										(OUT_EX6 + 0x05)
#define OUT_PIO_06										(OUT_EX6 + 0x06)
#define OUT_PIO_07										(OUT_EX6 + 0x07)


#endif
